﻿package com.codingbros.zigzag.lines
{		
	import flash.display.Shape;
		
	import flash.geom.Point;
		
	//zigzag line
	public final class Line extends Shape implements ILine
	{
		
		private static const ZIGZAGWIDTHNUM:int = 10;
		private static const ZIGZAGHEIGHTNUM:int = 7;
		
		private static const POINTREPLACEMENT:Number = 7.5;
		
		private var myZigZagPatternSize:int;
		
		private var myZigZagPoints:Array;
		
		public function Line(theParentWidth:int)
		{
			
			myZigZagPatternSize = theParentWidth / ZIGZAGWIDTHNUM;
			
			myZigZagPoints = new Array(ZIGZAGWIDTHNUM + 1);
			
			var lastYNum:Number = -1;
			
			for (var i:int = 0; i < myZigZagPoints.length; i ++)
			{
				var tempPoint:Point;
				var currentYNum:Number = Math.round(Math.random()*ZIGZAGHEIGHTNUM);
				while (currentYNum == lastYNum)
				{
				currentYNum = Math.round(Math.random()*ZIGZAGHEIGHTNUM);
				}			
				lastYNum = currentYNum;
				var tempY:Number = currentYNum * myZigZagPatternSize + Math.random() * POINTREPLACEMENT;
				
				tempPoint = new Point(i * myZigZagPatternSize + Math.random() * POINTREPLACEMENT, tempY);
				myZigZagPoints[i] = tempPoint;
			}
		}
	
		public function update():void { };
	
		public function reset():void { };
	
		public function draw():void
		{
			
			this.graphics.lineStyle(1,0x000000, 0.2);
			this.graphics.moveTo(myZigZagPoints[0].x, myZigZagPoints[0].y);
			for(var i:int = 1; i < myZigZagPoints.length; i ++){
				this.graphics.lineTo(myZigZagPoints[i].x, myZigZagPoints[i].y);
			}		
		}
	}
}